Component({
  properties: {
    marqueeText: {
      type: String,
      value: ''
    },
    marqueePace: { // 滚动速度
      type: Number,
      value: 0.2,
    },
  },
  data: {
    scrollStyle:'',
    viewTLength:'',
    textLength:'',
    isText:true,
  },
  attached() {
    
  },
  ready(){
    this.getInit()
  },
  methods: {
   async getInit() {
     var _this = this
      //创建节点选择器
       tt.createSelectorQuery().select('.scroll-text-warp').boundingClientRect().exec(res=>{
        this.setData({
          viewTLength:res[0].width
        });
        tt.createSelectorQuery().select('.scroll-text').boundingClientRect().exec(vo=>{
          this.setData({
             textLength:vo[0].width
          });
          _this.assignment()
        })
        // console.log('res[0].width',res[0].width)
      })
    },
    // 赋值
    assignment(){
      var textLength = this.data.textLength
      var viewTLength = this.data.viewTLength
      if(viewTLength > textLength){
        var scrollStyle = `animation: none;`;
        this.setData({
          isText:true,
          scrollStyle:scrollStyle
        });
      }else{
        var marqueeTextLength = this.properties.marqueeText.length;
        var animationDuration = marqueeTextLength * this.properties.marqueePace + 's';
        var scrollStyle = `animation: scrollText ${animationDuration} linear infinite;`;
        this.setData({
          isText:false,
          scrollStyle:scrollStyle
        });
      }
    },
  },
});
